import pymysql

db = pymysql.connect(host='localhost', user='root', password='123456',port=3306, database='test')
cursor = db.cursor()
sql="DELETE FROM EMPLOYEE WHERE AGE>'%d'" %(40)
try:
    cursor.execute(sql)
    db.commit()
except:
    db.rollback()

db.close()